// ctimeDemo 时间函数的应用
// Created by Administrator on 2025/6/26.
//

#include <complex>
#include <iostream>
using namespace std;

/**
 * time_t ：返回当前秒级时间戳
 * tm ：返回时间结构，可以获取时间基础信息字段（年，月，日，……）
 *
 */
void testFunc() {
    // second timestamp
    const time_t now = time(NULL);
    cout << "current timestamp：" << now << endl;

    // get time structure
    const struct tm *local_tm = localtime(&now);
    cout << "year：" << (local_tm->tm_year + 1900) << endl;
    cout << "mon：" << (local_tm->tm_mon + 1) << endl;
    cout << "day：" << local_tm->tm_mday << endl;

    // formate time
    char buf[80];
    strftime(buf, 80, "%Y-%m-%d %H:%M:%S", local_tm);
    cout << "current time:\t" << buf << endl;

    // get UTC time structure
    const struct tm *uct_tm = gmtime(&now);

    char uctBuf[80];
    strftime(uctBuf, 80, "%Y-%m-%d %H:%M:%S", uct_tm);
    cout << "current UTC time:\t" << uctBuf << endl;
}


int main(int argc, char *argv[]) {
    testFunc();
    return 0;
}
